package com.xc.h05.controller.renMengBinController;

import com.github.pagehelper.PageInfo;
import com.xc.h05.entity.ConsultlevelRMB;

import com.xc.h05.service.renMengBinService.ConsultlevelService;
import com.xc.h05.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/consultlevel")
public class ConsultlevelController {
    @Autowired
    private ConsultlevelService consultlevelService;
    //查询所有
    @GetMapping("/selectAll")
    public R selectAll(
            @RequestParam(value = "pageNum",required = false,defaultValue = "1") int pageNum,
            @RequestParam(value = "pageSize",required = false,defaultValue = "10") int pageSize,
            ConsultlevelRMB consultlevel
    ){
        PageInfo<ConsultlevelRMB> list = consultlevelService.selectAll(pageNum, pageSize,consultlevel);
        return R.ok(list);
    }

    //添加分类
    @PostMapping("/add")
    public R add(@RequestBody ConsultlevelRMB consultlevel){
        int i = consultlevelService.add(consultlevel);
        if (i>0){
            return R.ok("添加成功");
        }
        return R.fail("添加失败");
    }

    //删除分类
    @DeleteMapping("/remove/{id}")
    public R remove(@PathVariable("id") int id){
        int i = consultlevelService.remove(id);
        if (i>0){
            return R.ok("删除成功");
        }
        return R.fail("删除失败");
    }
    //修改分类
    @PutMapping("/update")
    public R update(@RequestBody ConsultlevelRMB consultlevel){
        int i = consultlevelService.update(consultlevel);
        if (i>0){
            return R.ok("修改成功");
        }
        return R.fail("修改失败");
    }
}
